package com.lihao.sam.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lihao.sam.dao.HealthCheckDao;
import com.lihao.sam.dao.HealthStatisticsDao;
import com.lihao.sam.dto.CompanyEmpCountDto;
import com.lihao.sam.dto.HealthCheckDto;
import com.lihao.sam.entity.HealthCheck;
import com.lihao.sam.entity.HealthStatistics;
import com.lihao.sam.service.intf.HealthCheckService;
import com.lihao.sam.vo.PageVo;
import com.lihao.sam.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 赵申奥
 * @Description:
 */
@Service
public class HealthCheckServiceImpl implements HealthCheckService {
    @Resource
    private HealthCheckDao dao;
    @Override
    public R add(HealthCheck healthCheck) {
        if(dao.add(healthCheck)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R update(HealthCheck healthCheck) {
        if(dao.update(healthCheck)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R delete(int id) {
        if(dao.delete(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }


    @Override
    public PageVo queryPage(String address, String buildNo, String floorNo, int page, int limit) {
        PageHelper.startPage(page, limit);
        PageInfo<HealthCheck> pageInfo=new PageInfo<>(dao.selectAll(address, buildNo, floorNo));
        return PageVo.ok(pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public R queryCount() {
        List<HealthCheckDto> list = dao.selectCount();
        //2.组装结果数据
        Map<String, ArrayList> map = new HashMap<>();
        map.put("address", new ArrayList());
        map.put("num", new ArrayList());
        for (HealthCheckDto dto : list) {
            map.get("companyName").add(dto.getAddress());
            map.get("num").add(dto.getNum());
        }
        return R.ok(map);
    }
}
